<?php
/** @var OrdenCompraController $this */
/** @var OrdenCompra $model */
$this->menu = array(
    array('label' => Yii::t('AweCrud.app', 'Manage'), 'icon' => 'list-alt', 'url' => array('admin'), 'itemOptions' => array('class' => 'active')),
//    array('label' => Yii::t('AweCrud.app', 'Create'), 'icon' => 'plus', 'url' => array('create')),
        //array('label' => "<div>" . CHtml::image(Yii::app()->baseUrl . "/images/topbar/administrar.png") . "</div>" . Yii::t('AweCrud.app', 'Manage'), 'itemOptions' => array('class' => 'active')),
);
?>


<div class="widget purple">
    <div class="widget-title">
        <h4><i class="icon-briefcase"></i> <?php echo Yii::t('AweCrud.app', 'Manage') ?> <?php echo OrdenCompra::label(2) ?></h4>
        <span class="tools">
            <a href="javascript:;" class="icon-chevron-down"></a>
            <!--a href="javascript:;" class="icon-remove"></a-->
        </span>
    </div>
    <div class="widget-body" style="padding-bottom: 150px">
        <?php
        $this->widget('bootstrap.widgets.TbExtendedGridView', array(
            'id' => 'orden-compra-grid',
            'type' => 'striped condensed',
            'dataProvider' => $model,
            'enableSorting' => false,
//    'filter' => $model,
            'columns' => array(
                //nombre del producto
                array(
                    'name' => 'producto_id',
                    'value' => 'Producto::model()->findByPk($data->producto_id)->nombre',
                ),
                //precio del producto
                array(
                    'name' => 'producto_precio',
                    'header' => 'Precio unitario',
                    'value' => 'Producto::model()->findByPk($data->producto_id)->precio_unitario',
                ),
//                'cantidad',
                array(
                    'name' => 'cantidad',
                    'header' => 'Cantidad',
                    'class' => 'bootstrap.widgets.TbEditableColumn',
                    'headerHtmlOptions' => array('style' => 'width:80px'),
                    'editable' => array(
                        'type' => 'text',
                        'url' => Yii::app()->baseUrl . '/productos/ordenCompra/listarorden',
                        'onSave' => 'js:function(){
                            location.reload();
                            }
                            '
                    )
                ),
                //total
                array(
                    'name' => 'producto_total',
                    'header' => 'Total',
                    'value' => 'Producto::model()->findByPk($data->producto_id)->precio_unitario *$data->cantidad ',
                ),
                //borrar producto
                array(
                    'class' => 'bootstrap.widgets.TbButtonColumn',
                    'template' => '{delete}'
                ),
            ),
            'template' => "{items}{extendedSummary}",
//borrar N productos
//            'bulkActions' => array(
//                'actionButtons' => array(
//                    array(
//                        'id' => '1',
//                        'buttonType' => 'button',
//                        'type' => 'warning',
//                        'size' => 'small',
//                        'label' => 'Eliminar Producto(s)',
//                        'click' => 'js:function(e,values){
//                            console.log(values);
//                            }'
//                    )
//                ),
//                // if grid doesn't have a checkbox column type, it will attach
//                // one and this configuration will be part of it
//                'checkBoxColumnConfig' => array(
//                    'name' => 'id'
//                ),
//            ),
//subtotal
            'extendedSummary' => array(
//                'title' => 'SubTotal',
                'columns' => array(
//                    'cantidad',
                    'producto_total' => array('label' => 'SubTotal', 'class' => 'TbSumOperation'),
//                    'SubTotal' => array('label' => 'TEST', 'class' => 'TbSumOperation'),
                )
            ),
            'extendedSummaryOptions' => array(
                'class' => 'well pull-right invoice-block',
                'style' => 'width:300px;margin-top: 15px;'
            ),
        ));
        ?>
        <!--         <div class="form-actions">
                    <div class="form-actions-float">-->
        <form  action="/facturacion-hnr/productos/ordenCompra/listarorden" method="post">
            <?php
            if ($ordenId)
            {
                $this->widget('bootstrap.widgets.TbButton', array(
                    'buttonType' => 'submit',
                    'type' => 'primary',
                    'label' => Yii::t('AweCrud.app', 'Save'),
                    'icon' => 'ok',
                    'htmlOptions' => array(
                        'name' => 'ActionButton',
                        'confirm' => '¿Desea crear este pedido?',
                    ),
                ));
            }
            ?>
        </form>
        <!--                </div>
                </div>-->
        <p class="note">Los precios no incluyen I.V.A</p>
        <a class="btn btn-inverse  hidden-print" onclick="javascript:window.print();">Imprimir <i class="icon-print icon-big"></i></a>
    </div>
</div>